package com.mz.ozy.mvp.presenter;

import android.app.Activity;


import com.mz.ozy.base.BasePresenterImpl;
import com.mz.ozy.bean.OrderLogisticsInfoBean;
import com.mz.ozy.constants.Constants;
import com.mz.ozy.mvp.view.OrderLogisticsInfoContract;
import com.mz.ozy.net.MyObserver;
import com.mz.ozy.net.RetrofitUtils;
import com.mz.ozy.utils.JsonUtils;
import com.mz.ozy.utils.RxUtil;

import java.util.HashMap;
import java.util.Map;

import okhttp3.ResponseBody;

/**
 * Created by Administrator on 2018/12/17.
 */

public class OrderLogisticsInfoPresenter extends BasePresenterImpl<OrderLogisticsInfoContract.View> implements OrderLogisticsInfoContract.Presenter {

    @Override
    public void initData(Activity activity, String order, int beanType) {
//        68、查看物流（ViewLogisticsV1）
//        请求参数
//
//        参数名称	参数值	必须	说明
//        transCode		必须	ViewLogisticsV1
//        t			Token
//        tseq		必须	订单号
        if (beanType == 0) {
            Map<String, String> maps = new HashMap<>();
            maps.put("tesq", order);//TransCode10022
//            maps.put("code", code);
//            maps.put("number", number);
            RetrofitUtils.getApiService(activity).post(Constants.TransCode.TransCode10022, JsonUtils.requestJsonDate(maps), Constants.tokenId)
                    .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                    .subscribe(new MyObserver<OrderLogisticsInfoBean>(mView, false) {
                        @Override
                        public void onSuccesss(OrderLogisticsInfoBean orderLogisticsInfoBean) {
                            mView.onInitSuccess(orderLogisticsInfoBean);
                        }
                    });
        } else {
            Map<String, String> maps = new HashMap<>();
            maps.put("tesq", order);
            RetrofitUtils.getApiService(activity).post(Constants.TransCode.TransCode10100, JsonUtils.requestJsonDate(maps), Constants.tokenId)
                    .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                    .subscribe(new MyObserver<OrderLogisticsInfoBean>(mView, false) {
                        @Override
                        public void onSuccesss(OrderLogisticsInfoBean orderLogisticsInfoBean) {
                            mView.onInitSuccess(orderLogisticsInfoBean);
                        }
                    });
        }
    }
    @Override
    public void getLogistics(Activity activity, String code, String number){
        Map<String, String> maps = new HashMap<>();
        maps.put("code", code);
        maps.put("number", number);
        RetrofitUtils.getApiService(activity).post(Constants.TransCode.TransCode10329, JsonUtils.requestJsonDate(maps), Constants.tokenId)
                .compose(RxUtil.rxSchedulerHelper(mView.<ResponseBody>bindToLifecycle()))
                .subscribe(new MyObserver<OrderLogisticsInfoBean>(mView, false) {
                    @Override
                    public void onSuccesss(OrderLogisticsInfoBean orderLogisticsInfoBean) {
                        mView.getLogisticsSuccess(orderLogisticsInfoBean);
                    }
                });
    }
}
